package com.greensoftcodeplus.redislog;


import com.alibaba.fastjson.JSONObject;

import com.greensoftcodeplus.redislog.services.MyServiceRs;
import com.greensoftcodeplus.redislog.utils.ResolvingFun;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;

@RunWith(SpringRunner.class)
@SpringBootTest

public class MyTest01 {


    @Autowired
    MyServiceRs myServiceRs;
   //"SETEX" "person1" 300 "{\"id\":1,\"name\":\"测试数据\",\"primarykey\":\"test::55\"}"
    @Test
    public void test01() {
        Person person = new Person();
        person.setId(1);
        person.setName("testdata");
        person.setPrimarykey("test::55");
        myServiceRs.set(person.getPrimarykey(), person, 600);

    }

    @Test
    public void test01_1() {

        myServiceRs.set("test1::1", "test1", 600);
        myServiceRs.set("test1::2", "test2");
    }

    @Test
    public void test02() {
        Person person = new Person();
        person.setId(1);
        person.setName("123");
        person.setPrimarykey("test::55");

        Person person1 = new Person();
        person1.setId(2);
        person1.setName("234");
        person1.setPrimarykey("test::66");

        List<Person> list=new ArrayList<>();
        list.add(person);
//        list.add(person1);
        myServiceRs.lSet("lset", list, 300);
//        for (int i=0;i<list.size();i++) {
//            myServiceRs.lSet("personlst", list.get(i), 300);
//        }
    }

    @Test
    public void test02_1() {
        Person person = new Person();
        person.setId(1);
        person.setName("123");
        person.setPrimarykey("test::55");

        Person person1 = new Person();
        person1.setId(2);
        person1.setName("234");
        person1.setPrimarykey("test::66");

        Object[] arr=new Object[2];
        arr[0]=person;
        arr[1]=person1;
//        list.add(person1);
        myServiceRs.lSet("lset",arr, -1);
//        for (int i=0;i<list.size();i++) {
//            myServiceRs.lSet("personlst", list.get(i), 300);
//        }
    }

    @Test
    public  void  test03(){
        Person person = new Person();
        person.setId(1);
        person.setName("测试数据");
        person.setPrimarykey("test::55");
        final byte[] bytes = ResolvingFun.SerializeObject(person);
    }
   //"GET" "person1"
    @Test
    public  void  test04(){
        Person person = new Person();
        person.setId(1);
        person.setName("测试数据");
        person.setPrimarykey("test::55");
        myServiceRs.set("person1",person ,3000);

        Object o = myServiceRs.get("person1");
        System.out.println(JSONObject.toJSONString(o));

    }
    @Test
    public  void  test05(){
        Set<String> set = myServiceRs.getLike("*test*");

        for (String v :set){
            System.out.println(v);
        }
    }
    @Test
    public  void  test06(){
        Object o = myServiceRs.lGet("personlst",0,10);
        System.out.println(JSONObject.toJSONString(o));

    }
    //判断键是否存在
    @Test
    public  void  test07(){
        boolean person1 = myServiceRs.hasKey("person1");
        if (person1){
            System.out.println("存在键");
        }
        else
            System.out.println("不存在键");
    }
    //自增量
    @Test
    public  void  test08()
    {
        long incr = myServiceRs.incr("incr", 1);
        System.out.println("自增量值" + incr);

    }
    //哈希表
    @Test
    public  void  test09()
    {
        HashMap stringHashMap = new HashMap<> ();
        stringHashMap.put("k1","v1");
        stringHashMap.put("k2","v2");
        boolean hash = myServiceRs.hmset("hash", stringHashMap);

    }
    @Test
    public  void  test10()
    {

        Object hget = myServiceRs.hget("hash", "k1");
        System.out.println(hget);


    }

    @Test
    public  void  test11()
    {

        HashMap stringHashMap = new HashMap<> ();
        stringHashMap.put("k1","v1");
        stringHashMap.put("k2","v2");
        boolean hash = myServiceRs.hmset("hash", stringHashMap,6000);


    }
    @Test
    public  void  test12()
    {

        Person person = new Person();
        person.setId(1);
        person.setName("person");
        person.setPrimarykey("person::11");

        HashMap stringHashMap = new HashMap<> ();
        stringHashMap.put("k1","v1");
        stringHashMap.put("k2","v2");
        stringHashMap.put("k3",person );
        boolean hash = myServiceRs.hmset("hashs", stringHashMap,-1);

    }

    @Test
    public  void  test14()
    {

        Person person = new Person();
        person.setId(1);
        person.setName("person");
        person.setPrimarykey("person::11");

        HashMap stringHashMap = new HashMap<> ();
        stringHashMap.put("k1","v1");
        stringHashMap.put("k2","v2");
        stringHashMap.put("k3",person );
        boolean hash = myServiceRs.hset("hash", "k4" ,stringHashMap);

    }

    @Test
    public  void  test15()
    {

        Person person = new Person();
        person.setId(1);
        person.setName("person");
        person.setPrimarykey("person::11");

        HashMap stringHashMap = new HashMap<> ();
        stringHashMap.put("k1","v1");
        stringHashMap.put("k2","v2");
//        stringHashMap.put("k3",person );
        boolean hash = myServiceRs.hset("hash", "k4" ,stringHashMap,100000);

    }
    @Test
   public void  test16(){
        long expire = myServiceRs.getExpire("hash");
        System.out.println(expire);
    }
    @Test
    public void  test17(){
       myServiceRs.del("hash");

    }
    @Test
    public  void  test18(){
        myServiceRs.decr("decr",1);
    }
    @Test
    public  void  test19(){
        Object hashs = myServiceRs.hget("hashs", "k3");
        System.out.println(hashs);
    }

    @Test
    public  void  test20(){
        Object hashs = myServiceRs.hmget("hashs");
        System.out.println(hashs);
    }
    @Test
    public  void  test21(){
         myServiceRs.hdel("hashs","k3");
    }
    @Test
    public  void  test22(){
        boolean b = myServiceRs.hHasKey("hashs", "k1");
        if (b) System.out.println("存在"); else  System.out.println("不存在");
    }
    @Test
    public  void  test23(){
        double hincr = myServiceRs.hincr("hincr", "hincr1", 2);
        System.out.println(hincr);


    }
    @Test
    public  void  test24(){
        double hincr = myServiceRs.hdecr("hincr", "hincr1", 2);
        System.out.println(hincr);
    }
    @Test
    public  void  test25(){
        Set<Object> personlst = myServiceRs.sGet("personlst");

    }
     

    @Test
    public  void  test26(){
        boolean personlst = myServiceRs.sHasKey("personlst", "k1");
        if (personlst) System.out.println("存在");
        else
            System.out.println("not存在");

    }
    @Test
    public  void  test27(){
        myServiceRs.sSet("sSET", "122", "122121", "323232");
    }
    @Test
    public  void  test28(){
        myServiceRs.sSetAndTime("sSET", 60000,"444", "555", "666");
    }

    @Test
    public  void  test29(){
        Person person = new Person();
        person.setId(1);
        person.setName("person");
        person.setPrimarykey("person::11");

        myServiceRs.sSetAndTime("sSET", 60000,"777", person);
    }
    @Test
    public  void  test30(){
        long sSET = myServiceRs.sGetSetSize("sSET");
        System.out.println(sSET);

    }

//    setRemove
@Test
public  void  test31(){
    Person person = new Person();
    person.setId(1);
    person.setName("person");
    person.setPrimarykey("person::11");
   myServiceRs.setRemove("sSET",person);
}
    @Test
    public  void  test32(){

        System.out.println(myServiceRs.lGetListSize("lset"));
    }

    @Test
    public  void  test33(){
        System.out.println(myServiceRs.lGetIndex("lset",1));
    }

    @Test
    public  void  test34(){
        System.out.println(myServiceRs.lSet("lset","12212121"));
    }

    @Test
    public  void  test35(){
        System.out.println(myServiceRs.lUpdateIndex("lset",1,"1233212121"));
    }

    @Test
    public  void  test36(){
        System.out.println(myServiceRs.lRemove("lset",1,"1233212121"));
    }

}
